package org.smoozik.services.musictheory;

import java.util.ArrayList;

import org.smoozik.app.ihm.Constants;

public class Progression {
	public static final Degree I = new Degree(Constants.UNISSON,
			Constants.MAJ7, Constants.MODE1_SCALE);
	public static final Degree II = new Degree(Constants.SECONDE,
			Constants.MIN7, Constants.MODE2_SCALE);
	public static final Degree III = new Degree(Constants.TIERCE,
			Constants.MIN7, Constants.MODE3_SCALE);
	public static final Degree IIIM7 = new Degree(Constants.TIERCE,
			Constants.M7, Constants.MODE3_SCALE_MAJ);
	public static final Degree IV = new Degree(Constants.QUARTE,
			Constants.MAJ7, Constants.MODE4_SCALE);
	public static final Degree V = new Degree(Constants.QUINTE, Constants.M7,
			Constants.MODE5_SCALE);
	public static final Degree VI = new Degree(Constants.SIXTE, Constants.MIN7,
			Constants.MODE6_SCALE);
	public static final Degree VII = new Degree(Constants.SEPTIEME,
			Constants.DIM7, Constants.MODE7_SCALE);

	public static final Degree BLUES_I = new Degree(Constants.UNISSON,
			Constants.M7, Constants.MODE6_SCALE);
	public static final Degree BLUES_II = new Degree(Constants.QUARTE,
			Constants.M7, Constants.MODE6_SCALE);
	public static final Degree BLUES_III = new Degree(Constants.QUINTE,
			Constants.M7, Constants.MODE6_SCALE);

	public static final Degree[] BLUES = { BLUES_I, BLUES_I, BLUES_I, BLUES_I,
			BLUES_II, BLUES_II, BLUES_I, BLUES_I, BLUES_III, BLUES_II, BLUES_I,
			BLUES_III };

	public static final Degree[] BASIC = { I, II, III, IV, V, VI, VII };

	public static final Degree[] JAZZ = { II, V, I, IV, VII, IIIM7, VI, VI};

	private ArrayList<Degree> degrees;
	private Note root;

	public Progression() {
		degrees = new ArrayList<>();
	}

	public Progression(Note note) {
		this();
		root = note;
	}

	public Progression(Degree[] list) {
		degrees = new ArrayList<>();

		for (Degree degree : list) {
			degrees.add(degree);
		}
	}

	public Progression(Note note, Degree[] list) {
		this(list);
		root = note;
	}

	public ArrayList<Degree> getDegrees() {
		return degrees;
	}

	public void setDegrees(ArrayList<Degree> degrees) {
		this.degrees = degrees;
	}

	public Scale getScale(int index) {
		Degree d = degrees.get(index);

		Scale s = d.getScaleForRoot(root);

		return s;
	}

	public Chord getChord(int index) {
		Degree d = degrees.get(index);

		Chord s = d.getChordForRoot(root);

		return s;
	}

	public Note getNote(int index) {
		Degree d = degrees.get(index);

		Note s = d.getNoteForRoot(root);

		return s;
	}

	public Degree getDegree(int index) {
		return degrees.get(index);
	}

	public static void main(String[] args) {
		Note n = new Note(5);
		Progression p = new Progression(n, BLUES);

		// Notes
		// for (int i = 0; i < p.getDegrees().size(); i++) {
		// System.err.println(p.getNote(i));
		// }
		// Chords
		for (int i = 0; i < p.getDegrees().size(); i++) {
			System.err.println(p.getChord(i));
		}

		// Scales
		// for (int i = 0; i < p.getDegrees().size(); i++) {
		// System.err.println(p.getScale(i));
		// }
	}

}
